package com.sxu.greedy.day3;

import java.util.Arrays;

/**
 * 按身高排序
 */
public class TestSort {
    public String[] sortPeople(String[] names, int[] heights) {
        int n = names.length;
        // 创建下标数组
        Integer[] index = new Integer[n];
        for (int i = 0; i < n; i++) {
            index[i] = i;
        }
        // 对下标数组排序
        Arrays.sort(index, (i,j)->{
            return heights[j]-heights[i];
        });
        // 提取结果
        String[] ret = new String[n];
        for (int i = 0; i < n; i++) {
            ret[i] = names[index[i]];
        }
        return ret;
    }
}
